package com.vanpos.web.system;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.vanpos.criteria.system.LoginCommand;
import com.vanpos.domain.user.OperatorUser;
import com.vanpos.service.user.OperatorUserService;

@Controller
public class LoginController {
	@Autowired
	private OperatorUserService operatorUserService;
	
	@RequestMapping(value="/index.html")
	public String loginPage(){
		System.out.println("我阿萨德发送到发射点发");
		return "login";
	}
	
	/**
	 * 登录处理模块
	 * @param request
	 * @param loginCommand
	 * @return
	 */
	@RequestMapping(value="/loginCheck.html")
	public ModelAndView loginCheck(HttpServletRequest request, LoginCommand loginCommand){
		boolean isValidUser = operatorUserService.getMatchCount(loginCommand.getLoginName(), loginCommand.getPassword());
		System.out.println("执行了此操作！！！"+loginCommand.getLoginName());
		if(!isValidUser){
			return new ModelAndView("login","error","用户名或密码错误！");
		}else{
			OperatorUser operatorUser = operatorUserService.findUserByLoginName(loginCommand.getLoginName());
			request.setAttribute("user", operatorUser);
			return new ModelAndView("layout");
		}
	}
}
